<template>
  <div class="dashboard-container">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card>
          <div class="statistic-card">
            <div class="statistic-title">员工总数</div>
            <div class="statistic-value">{{ stats.employeeCount }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div class="statistic-card">
            <div class="statistic-title">商品总数</div>
            <div class="statistic-value">{{ stats.productCount }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div class="statistic-card">
            <div class="statistic-title">供应商数量</div>
            <div class="statistic-value">{{ stats.supplierCount }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div class="statistic-card">
            <div class="statistic-title">库存总量</div>
            <div class="statistic-value">{{ stats.totalStock }}</div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-card style="margin-top: 20px;">
      <h3>库存预警</h3>
      <el-table :data="lowStockProducts" border>
        <el-table-column prop="code" label="商品编码" />
        <el-table-column prop="name" label="商品名称" />
        <el-table-column prop="stock" label="库存" />
        <el-table-column prop="warning_stock" label="预警库存" />
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import request from '@/utils/request'
import { ElMessage } from 'element-plus'

const stats = ref({
  employeeCount: 0,
  productCount: 0,
  supplierCount: 0,
  totalStock: 0
})

const lowStockProducts = ref([])

const getStats = async () => {
  try {
    // 这里需要后端接口支持统计信息
    // 暂时使用 mock 数据
    stats.value = {
      employeeCount: 25,
      productCount: 89,
      supplierCount: 34,
      totalStock: 1200
    }
  } catch (error) {
    console.error('获取统计数据失败:', error)
  }
}

const getLowStockProducts = async () => {
  try {
    // 这里应该调用库存预警接口
    lowStockProducts.value = [
      { code: 'P001', name: '商品A', stock: 5, warning_stock: 10 },
      { code: 'P003', name: '商品C', stock: 8, warning_stock: 10 },
      { code: 'P005', name: '商品E', stock: 3, warning_stock: 5 }
    ]
  } catch (error) {
    console.error('获取库存预警失败:', error)
  }
}

onMounted(() => {
  getStats()
  getLowStockProducts()
})
</script>

<style scoped>
.dashboard-container {
  padding: 20px;
}

:deep(.el-card) {
  border-radius: 12px;
  border: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

:deep(.el-card:hover) {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.statistic-card {
  text-align: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.statistic-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, #1890ff, #36cfc9);
}

.statistic-title {
  font-size: 16px;
  color: #666;
  margin-bottom: 15px;
  font-weight: 500;
}

.statistic-value {
  font-size: 32px;
  font-weight: 600;
  background: linear-gradient(45deg, #1890ff, #36cfc9);
  -webkit-background-clip: text;
  color: transparent;
  margin-bottom: 10px;
}

:deep(.el-table) {
  border-radius: 8px;
  overflow: hidden;
}

:deep(.el-table th) {
  background-color: #f8f9fa !important;
  font-weight: 600;
  color: #333;
}

:deep(.el-table td) {
  padding: 12px 0;
}

:deep(.el-table--border) {
  border: 1px solid #ebeef5;
}

:deep(.el-table--border .el-table__cell) {
  border-right: 1px solid #ebeef5;
}

:deep(.el-card__header) {
  padding: 16px 20px;
  border-bottom: 1px solid #ebeef5;
  font-weight: 600;
  color: #333;
}

:deep(.el-card__body) {
  padding: 20px;
}

h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 20px;
}

.el-row {
  margin-bottom: 20px;
}

:deep(.el-table__row:hover) {
  background-color: #f5f7fa !important;
}

:deep(.el-table__row) {
  transition: all 0.3s ease;
}

:deep(.el-table__row:hover) {
  transform: scale(1.01);
}
</style>
